package com.niuxiaofa.newlaw.Activity;

import android.graphics.Color;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Base.BaseActivity;
import com.niuxiaofa.newlaw.Bean.RankingBean;
import com.niuxiaofa.newlaw.Network.LawUniversalPresenter;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.GlideUtils;
import com.niuxiaofa.newlaw.Tools.RecyclerViewHelp;
import com.niuxiaofa.newlaw.adapter.AwardRankingAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import www.linwg.org.lib.LCardView;


/**
 * 嘉奖排行
 */
public class AwardRankingActivity extends BaseActivity implements LawUniversalPresenter.interface_getAwardsRanking {


    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;

    AwardRankingAdapter awardRankingAdapter;

    List<RankingBean.DataDTO> newsList = new ArrayList<>();


    @BindView(R.id.universal_law)
    LCardView universal_law;


    @BindView(R.id.reward)
    LCardView reward;


    @BindView(R.id.universal_text)
    TextView universal_text;

    @BindView(R.id.reward_text)
    TextView reward_text;


    @BindView(R.id.image1)
    ImageView image1;


    @BindView(R.id.image2)
    ImageView image2;


    @BindView(R.id.image3)
    ImageView image3;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_award_ranking;
    }

    @Override
    protected void initData() {

        setTitle("嘉奖排行");

        LawUniversalPresenter.getAwardsRanking("1", this);
        awardRankingAdapter = new AwardRankingAdapter(newsList, new AwardRankingAdapter.Onclick() {
            @Override
            public void onclick(int c) {

            }
        });
        RecyclerViewHelp.setRecycler(recyclerview, 0).setAdapter(awardRankingAdapter);


        universal_law.setOnClickListener(e -> {
            LawUniversalPresenter.getAwardsRanking("1", this);
            universal_law.setCardBackgroundColor(Color.parseColor("#FF141080"));
            reward.setCardBackgroundColor(Color.parseColor("#FF928ABC"));
            universal_text.setTextColor(Color.WHITE);
            reward_text.setTextColor(Color.parseColor("#FF0E14A1"));
        });

        reward.setOnClickListener(e -> {
            LawUniversalPresenter.getAwardsRanking("2", this);
            universal_law.setCardBackgroundColor(Color.parseColor("#FF928ABC"));
            reward.setCardBackgroundColor(Color.parseColor("#FF141080"));
            universal_text.setTextColor(Color.parseColor("#FF0E14A1"));
            reward_text.setTextColor(Color.WHITE);
        });

    }

    @Override
    public void getResponse(RankingBean u) {
        if (u.getCode() == 1) {
            newsList.clear();
            newsList.addAll(u.getData());
            if (u.getData().size() > 3) {

                GlideUtils.loadUserImg(getContext(), u.getData().get(0).getHeader(), image1);
                GlideUtils.loadUserImg(getContext(), u.getData().get(1).getHeader(), image2);
                GlideUtils.loadUserImg(getContext(), u.getData().get(2).getHeader(), image3);
            }


            awardRankingAdapter.notifyDataSetChanged();
        }
    }
}
